#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 导入 BeautifulSoup 与 requests
from bs4 import BeautifulSoup
import requests

# 主页
URL = 'https://baike.baidu.com/item'

# 头信息
header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) Gecko/20100101 Firefox/57.0'}

# 定义获取词条摘要的函数
def get_summary(item:str) -> str:
    # 获取摘要
    url = URL + '/' + item
    resp = requests.get(url, headers=header_dict)
    soup = BeautifulSoup(resp.content.decode('utf-8'), "lxml")  # 构造 BeautifulSoup
    #summary = soup.find('div', {'class':'lemma-summary'})       # 搜索 tag, 传入tag名和键值对
    summary = soup.select('body > div.body-wrapper.feature.feature_small.collegeSmall > div.feature_poster > div > div.poster-left > div.poster-top > div.lemma-summary')
    summary = summary[0]
    return summary.text                                       # 提取纯文本

item = '浙江工业大学之江学院'
print(get_summary(item))